import { actionType } from "../common/common_enum";
import IdleStatus from "./PlayerStatus/IdleStatus";
import RunStatus from "./PlayerStatus/RunStatus";
import WalkStatus from "./PlayerStatus/WalkStatus";
import { RootStatus } from "./RootStatus";

/**状态机 */
export default class StatusMachine{

    mapStatusInfo:Map<actionType, RootStatus> = new Map()

    curStatus:RootStatus = null;
    nCurStatusKey:actionType = actionType.Idle;


    getCurStatusKey():actionType
    {
        return  this.nCurStatusKey
    }

    changeStatus(status:actionType)
    {
        if (this.nCurStatusKey == status) return

        if(this.curStatus) //&& this.nCurStatusKey != status
        {
            this.curStatus.onExit();
        }

        let statusNow = this.mapStatusInfo.get(status);
        if(statusNow)
        {
            this.nCurStatusKey = status;
            this.curStatus = statusNow;
            statusNow.onEnter();
        }
    }

    mUpdate(dt)
    {
        if (this.curStatus) 
            this.curStatus.onUpdate(dt);
        
    }
}
